local InnerDataManagerFL = require("innerdata.InnerDataManagerFL")
local InnerDataDefine = require("innerdata.Define")
local ExcelMapConf = require("excel.Map")
local Map = require("core.Map")
local ObjMonster = require("core.ObjMonster")
local Util = require("common.Util")
local DailyActFL = require("activity.DailyActFL")
local ActDefine = require("activity.Define")
local Msg = require("core.Msg")
local Obj = require("core.Obj")

WildBossData = WildBossData or {}

function onGetEnterData(nMapID)
    return nMapID, ExcelMapConf.scene[nMapID].x, ExcelMapConf.scene[nMapID].y 
end

function onSendFirstHitData(human, sendArea)
    local nWildBossData = WildBossData[human.db.map_id]
    if not nWildBossData or not nWildBossData.boss then
        return
    end

    if not DailyActFL.onCheckActIsRunning(ActDefine.ACT_TYPE_WILDBOSS, nWildBossData.configID) then
        return
    end

    if nWildBossData.boss.firstHitUuid then
        local mm = Msg.gc.GC_CHANGE_FIRST_HIT_UUID
        mm.obj_id = nWildBossData.boss.id
        mm.firstHitUuid = nWildBossData.boss.firstHitUuid
        mm.firstHitName = nWildBossData.boss.firstHitName 
        mm.show = 1
        if sendArea then
            Obj.sendScene(mm, nWildBossData.boss.scene_id)
        else
            Msg.send(mm, human.fd)
        end
    end
end

function GetActConfigID(mapID)
    return WildBossData[mapID] and WildBossData[mapID].configID or nil
end

function onCreateBoss(nData)
    if DailyActFL.onCheckActIsRunning(ActDefine.ACT_TYPE_WILDBOSS, nData.data.configID) then
        return
    end
    local nMonsterID = nData.data.monsterID
    local nPosX = nData.data.posX
    local nPosY = nData.data.posY
    --HurtList = (HurtList and HurtList[nSceneID]) and HurtList[nSceneID] or {[nSceneID] = {}} 
    WildBossData[nData.data.mapID] = {boss = nil, mapID = nData.data.mapID, configID = nData.data.configID, curLastHitName = nil, curLastHitUuid = nil}

    local nMapID = nData.data.mapID
    local logicID = Map.get_logic_id(nMapID)
    if _G.logic_id == logicID then
        local nSceneID = Map.map_id_to_scene_id[nMapID][1]
        if nSceneID then
            local monster = ObjMonster.create(nMonsterID)
            ObjMonster.enterScene(monster, nSceneID, nPosX, nPosY)
            WildBossData[nData.data.mapID].boss = monster
        end
    end
end

function onDie(human)
    local nSceneID = human.scene_id
    if not nSceneID then
        return
    end
	local nMapID = Map.scene_id_to_map_id[nSceneID]
    local nBossData = WildBossData[nMapID]
    if not nBossData then
        return
    end
    nBossData.curLastHitUuid = human._id

    local nActData = DailyActFL.onGetActData(ActDefine.ACT_TYPE_WILDBOSS, nBossData.configID)
    if nActData then
        if nSceneID then
            local nSend2Wdata = {
                type = 1,
                data = {lastHit = {human.name, human._id}, actArgs = nActData.actArgs}
            }
            InnerDataManagerFL.Send2WInnerData(human, InnerDataDefine.INNERDATA_TYPE_WILDBOSS, nSend2Wdata)
        end
    end
end

function onGetBossLastHitData(mapID)
    if WildBossData[mapID] then
        return WildBossData[mapID].curLastHitUuid
    end
end

function onGetBossData(mapID)
    if WildBossData[mapID] and WildBossData[mapID].boss then
        return WildBossData[mapID].boss
    end
end

function onClose(nData)
    print("on Close")
    local nMapID = nData.data.mapID 
    local logicID = Map.get_logic_id(nMapID)
    if _G.logic_id == logicID then
        local nSceneID = Map.map_id_to_scene_id[nMapID][1]
        if nSceneID then

        end
    end
end
